package httpModels

import (
	"fmt"
	"github.com/google/uuid"
	"github.com/samber/lo"
	"time"
	"videoPlay/internal/commonModels"
	"videoPlay/internal/dal/dalModels"
)

type Video struct {
	RecordAt     time.Time      `json:"recordAt"`
	VideoId      uuid.UUID      `json:"videoId"`
	PreviewImg   string         `json:"previewImg"`
	Src          string         `json:"src"`
	Name         string         `json:"name"`
	VideoTags    []*VideoTag    `json:"videoTags"`
	DurationTags []*DurationTag `json:"durationTags"`
}

func (v *Video) FromDalModel(vv *dalModels.Video) *Video {
	v.RecordAt = vv.RecordAt
	v.VideoId = vv.Id
	v.PreviewImg = fmt.Sprintf("api/video/%s/preview", v.VideoId)
	v.Src = fmt.Sprintf("api/video/%s/media", v.VideoId)
	v.Name = vv.Name
	v.VideoTags = lo.Map(vv.VideoTags, func(tag dalModels.VideoTag, index int) *VideoTag {
		return new(VideoTag).FromDalModel(tag)
	})
	v.DurationTags = lo.Map(vv.DurationTags, func(starDuration dalModels.DurationTag, _ int) *DurationTag {
		return new(DurationTag).FromDalModel(starDuration)
	})
	return v
}

type VideoTag struct {
	Id      uint   `json:"id"`
	Content string `json:"content"`
}

func (v *VideoTag) FromDalModel(vv dalModels.VideoTag) *VideoTag {
	v.Id = vv.ID
	v.Content = vv.Content
	return v
}

type DurationTag struct {
	Id      uint   `json:"id"`
	Second  int64  `json:"second"`
	Content string `json:"content"`
}

func (d *DurationTag) FromDalModel(dd dalModels.DurationTag) *DurationTag {
	d.Id = dd.ID
	d.Second = dd.Second
	d.Content = dd.Content
	return d
}

type ReqGetVideoList struct {
	commonModels.Pager
	Keywords string `json:"keywords" form:"keywords"`
}

type RespGetVideoList struct {
	commonModels.Pager
	Data []*Video `json:"data"`
}

type ReqDeleteVideo struct {
	Password string `json:"password" binding:"required"`
}

type RespDeleteVideo struct {
	VideoId uuid.UUID `json:"videoId"`
}

type ReqAddVideoTagForVideo struct {
	Name string `json:"name" binding:"required"`
}

type RespDeleteVideoTag struct {
	Id uint `json:"id"`
}

type ReqAddDurationTagForVideo struct {
	StarSecond int64  `json:"starSecond" binding:"required"`
	Content    string `json:"content" binding:"required"`
}

type RespDeleteDurationTag struct {
	Id uint `json:"id"`
}

type ReqGetVideoByRandom struct {
	Keywords string `json:"keywords" form:"keywords"`
}
